package tests.gui;

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class Main extends JFrame {
    MyLabel label;
    public static void main(String[] args) {
        new Main().setVisible(true);
    }
    public Main(){
        label=new MyLabel("Type Something!");
        add(label);
        setSize(0x400,0x400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
    }
    class MyLabel extends JLabel {
        public MyLabel(String text) {
            super(text);
            addKeyListener(new MyKeyAdapter());
            setVisible(true);
        }
        public void updateState(String s){
            setText(s);
            setVisible(true);
        }
        class MyKeyAdapter extends KeyAdapter {
            @Override
            public void keyPressed(KeyEvent e) {
                MyLabel.this.updateState(String.valueOf(e.getKeyChar()));
            }

            @Override
            public void keyTyped(KeyEvent e) {
                MyLabel.this.updateState(String.valueOf(e.getKeyChar()));
            }
        }
    }
}